<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <script>
    /*
promise.all([p1,p2,p3])可以将不同的promise实例放到一个promise实例当中，成功则返回成功的数据，失败返回最先失败reject的数据
promise.race([p1,p2,p3])返回所包含的promise实例当中运行结果最快的数据，哪个最快返回哪个，不管成功还是失败 */
    let p1 = new Promise((resolve, reject) => {
      resolve('p1 good')
    })

    let p2 = new Promise((resolve, reject) => {
      setTimeout(() => {
        resolve('p2 good')
      }, 1000)
    })

    let p3 = new Promise((resolve, reject) => {
      reject('bad')
    })
    Promise.all([p1, p2, p3]).then(res => {
      console.log(res);
    }).catch(err => {
      console.log(err);
    })
    Promise.race([p1, p2, p3]).then(res => {
      console.log(res);
    })
  </script>
</body>

</html>